package com.coocaa.internship.dao;

import com.coocaa.internship.pojo.UserLogin;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

/**
 * @Description: 登录用户Dao层
 * @Author: zwh
 * @Date: 2019-07-24
 * @Time: 23:18
 */
@Mapper
@Component
public interface UserLoginDao {
    String TABLE_NAME = "user_login";
    String INSERT_FILEDS_WITH_PHONE = "user_phone , user_role";
    String INSERT_FILEDS_WITH_PASS = "user_account , user_password ,user_role";
    String SELECT_FILEDS  = "user_id , user_phone ,  user_account , user_password , user_role";

    @Select({"select ",SELECT_FILEDS," from ", TABLE_NAME, " where user_account = #{userAccount} and user_password = #{userPassword}"})
    UserLogin selectUserLoginByPass(UserLogin userLogin);

    @Select({"select ",SELECT_FILEDS," from ", TABLE_NAME, " where user_phone = #{userPhone}"})
    UserLogin selectUserLoginByPhone(UserLogin userLogin);

    @Select({"select ", SELECT_FILEDS, " from ", TABLE_NAME, " where user_id = #{userId}"})
    UserLogin selectUserLoginById(@Param("userId") Long userId);


    @Insert({"insert into ",TABLE_NAME," ( ",INSERT_FILEDS_WITH_PHONE," ) values (#{userPhone} , #{userRole})"})
    @Options(useGeneratedKeys = true , keyColumn = "user_id" , keyProperty = "userId")
    Integer insertUserLoginByPhone(UserLogin userLogin);


    @Insert({"insert into ",TABLE_NAME," ( ",INSERT_FILEDS_WITH_PASS," ) values (#{userAccount} , #{userPassword} , #{userRole})"})
    @Options(useGeneratedKeys = true , keyColumn = "user_id" , keyProperty = "userId")
    Integer insertUserLoginByPass(UserLogin userLogin);

    Integer updateUserLogin(UserLogin userLogin);
}
